package com.hyfrogx.modules.app.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hyfrogx.common.utils.QueryExt;
import com.hyfrogx.modules.app.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author ：Li9527
 * @date ：Created in 2019-09-16 12:59
 * @description：${description}
 * @modified By：
 * @version: 1.0.0
 */
@Mapper
public interface UserDao extends BaseMapper<User> {

  List selectPageByConditions(QueryExt query, Map map);

  /**
   * 查询用户是否关注过资讯号
   *
   * @param uid
   * @return
   */
  @Select("select\n" +
    "\t\tcount(1)\n" +
    "\t\tFROM\n" +
    "\t\thy_user u\n" +
    "\t\tLEFT JOIN hy_user_attention a ON a.fid = u.uid\n" +
    "\t\tLEFT JOIN hy_information_verify v ON v.uid = a.sid\n" +
    "\t\tWHERE\n" +
    "\t\tv.verify_status = 1\n" +
    "\t\tAND v.enable_state = 1\n" +
    "\t\tAND u.uid = #{uid}\n" +
    "\t\tLIMIT 0,1")
  Integer getIsFollowNull(@Param("uid") Integer uid);

  @Select("select\n" +
    "\t\tuid,username,rid,email,birthday,head,sex,signature,created from\n" +
    "\t\thy_user where uid =\n" +
    "\t\t#{uid}")
  User getUserSelfInfoByUid(@Param("uid") Integer uid);

  @Select("select\n" +
          "\t\tu.*,r.name as roleName\n" +
          "\t\tfrom hy_user u\n" +
          "\t\tleft join\n" +
          "\t\thy_role r on r.rid = u.rid\n" +
          "\t\twhere u.uid = #{uid,jdbcType=INTEGER}")
  User selectByUid(Integer uid);

}
